package com.ccsoft.zknote.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.data.repository.init.ResourceReader;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ResourcesUtils {
    public void readResource(String resourcePath) {
        log.info("开始读取资源目录" + resourcePath);
        // 使用 ClassLoader 获取资源的 InputStream
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream(resourcePath)) {
            if (inputStream != null) {
                // 在这里处理 inputStream，例如读取内容或进行其他操作
                // 这里只是打印内容示例
                int data;
                log.info("读取资源目录成功，开始循环打印读到的内容");
                while ((data = inputStream.read()) != -1) {
                    log.info(String.valueOf((char) data));
                }
            } else {
                log.info("Resource not found: " + resourcePath);
            }
        } catch (IOException e) {
            log.info("读取资源目录" + resourcePath + "时出现异常！");
            e.printStackTrace();
        }
    }

//    public static void main(String[] args) {
//        ResourceReader resourceReader = new ResourceReader();
//        resourceReader.readResource("path/to/your/resource.txt");
//    }
}
